package cn.ml.gaoJi.jiHe.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

//集合中只能存对象
public class ArrayLiskDemo {
    public static void main(String[] args) {
        NewsTitle title1 = new NewsTitle(1,"1-北京晴天了1","admid");
        NewsTitle title2 = new NewsTitle(1,"2-北京晴天了2","admid");
        NewsTitle title3 = new NewsTitle(1,"3-北京晴天了3","admid");
        NewsTitle title4 = new NewsTitle(1,"4-北京晴天了4","admid");
        NewsTitle title5 = new NewsTitle(1,"5-北京晴天了5","admid");
        NewsTitle title6 = new NewsTitle(1,"6-北京晴天了5","admid");
        NewsTitle title7 = new NewsTitle(1,"7-北京晴天了5","admid");

        ArrayList list = new ArrayList();
        List list3 = new ArrayList();
        List list2 = new ArrayList();//list2只能调用List和ArrayList共有的方法，ArrayList独有的方法调用不了
        list.add(title1);
        list.add(title2);
        list.add(title3);
        list.add(title4);
        list.add(1,title5);//在1位置将title5加进去
        //list.add(3);//集合中只能存对象，基本类型存入会自动包装成对象
        list3.add(title5);
        list3.add(title6);
        list3.add(title7);
        list.addAll(list3);  // 将list3中所有元素添加到list1
        System.out.println("新闻标题总数："+list.size());
        //System.out.println(Collections.sort(list));
        //遍历新闻标题
        System.out.println("11----for循环---------------------");
        for(int i=0;i<list.size();i++){
            NewsTitle title = (NewsTitle) list.get(i);
            System.out.println(title.getTitle()+title.getAuthor());
        }
        System.out.println("222222----增强型for--------------------");
        for (Object s:list){
            NewsTitle title = (NewsTitle) s;
            System.out.println(title.getTitle()+title.getAuthor());
        }
        System.out.println("33333----iterator迭代器--------------------");
        Iterator itor = list.iterator();
        while (itor.hasNext()){
            NewsTitle title = (NewsTitle) itor.next();
            System.out.println(title.getTitle()+title.getAuthor());
        }
        System.out.println("**********************");
        System.out.println(list.contains(title1));//是否包含title1
        System.out.println("list移除title1："+list.remove(title1));//移除title1
        System.out.println("********************************************");

        list.clear();//清空list
        System.out.println("list大小："+list.size());
        System.out.println("lsit集合是否为空："+list.isEmpty());//list是否为空




    }

}
